// Block.cpp: implementation of the CBlock class.
//
//////////////////////////////////////////////////////////////////////
#include "iface.h"
#include "Block.h"
#include "Card.h"

extern int ShowCards;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBlock::CBlock()
{
	this->Init();
}

CBlock::~CBlock()
{

}

void	Fill() { ::Fill(); }

const char* CBlock::SlotName()
{
	return "Block";
}

bool CBlock::CheckPushPrecondition(const CCard &_card)
{
	return true;
}

void CBlock::Init()
{
	RemoveAll();
	this->Fill();
	this->Shuffle();
}

#define SPACE_CLOSED 2
#define SHOW_EVERY_N 4
void CBlock::CalculateDrawingArea( int& _x, int&  _y, int& _width, int& _height )
{
	// max cards in BLOCK (52)
	_x = 0 - ( (52+1)/SHOW_EVERY_N );
	_y = 0 - ( (52+1)/SHOW_EVERY_N );
	_width = CARD_WIDTH + (-1*_x);
	_height = CARD_HEIGHT + (-1*_y);
}

void CBlock::Draw(unsigned int _x, unsigned int _y, bool selected )
{
	std::cout << inf << "fill area: " << _x << "," << _y << std::endl;

	ClearDrawingArea(_x, _y);

	std::cout << inf << "paint cards: " << this->GetCardsStored() << std::endl;
	
	for( unsigned char i = 0; this->GetCardsStored() && i <= this->GetCardsStored() / SHOW_EVERY_N; i++ )
	{
		cardstack[0].Draw( _x - (i*SPACE_CLOSED), _y - (i*SPACE_CLOSED));
	}

	std::cout << inf << "or may be place holder?: " << this->GetCardsStored() << std::endl;
	
	if( !this->GetCardsStored() )
	{
		CCard::DrawPlaceHolder( _x, _y );
	}

	std::cout << inf << "and  may be the hand?: " << selected << std::endl;

	/* draw hand */
	if( selected )
	{
		CCard::DrawCursor( _x+20, _y+10 );
	}

}

bool CBlock::IncreaseSelection()
{
	if( cards_stored && cards_selected < ShowCards )
	{
		cards_selected++;
		return true;
	}
	return false;
}
